package com.thoughtworks.twu.module1;

import java.util.ArrayList;

public final class PrimeFactorsExercise {
    private PrimeFactorsExercise() {

    }

    public static void run() {
        run(1);
        run(4);
        run(10);
        run(20);
        run(23);
        run(119);
        run(120);
    }

    private static void run(int n) {
        Utilities.printTitle(String.format("generate(%d)", n));
        System.out.println(generate(n));
    }

    private static ArrayList<Integer> generate(int n) {
        ArrayList<Integer> factors = new ArrayList<Integer>();

        for (int i = 2; i <= n; i++) {
            while (n % i == 0) {
                if (!factors.contains(i)) {
                    factors.add(i);
                }

                n = n / i;
            }
        }

        return factors;
    }
}
